﻿using Microsoft.VisualStudio.TestTools.UnitTesting;
using System;
using System.IO;
using System.Collections.Generic;
using System.Linq;
using Liquifier;

namespace LiquifierTest
{
    public partial class LiquiferAttributesTest
    {
        [Liquifiable(Serialisation.None, Serialisation.Public)]
        public class ClassWithPropertiesWithArguments
        {
            public int Serialised { get; set; }
            
            public int this[int index]
            {
                get { return ind; }
                set { ind = value; }
            }

            int ind = -1;
        }

        [TestMethod]
        public void Ignores_Properties_With_Arguments()
        {
            var before = new ClassWithPropertiesWithArguments();

            before.Serialised = 20;
            before[0] = 21;

            var after = DoLiquifify(before);

            Assert.AreEqual(20, after.Serialised);
            Assert.AreEqual(-1, after[0]);
        }

        [Liquifiable(Serialisation.None, Serialisation.Public | Serialisation.Private | Serialisation.Explicit)]
        public class ClassWithAccessors
        {
            public int Property1 { get; set; }
            public int Property2 { get { return 10; } }
            public int Property3 { set { } }

        }

        [TestMethod]
        public void IgnoresPropertiesWithNoSetAccessors()
        {
            ClassWithAccessors before = new ClassWithAccessors();

            before.Property1 = 29;

            var after = DoLiquifify(before);

            MemoryTributary s = new MemoryTributary();
            var info = Liquifer.Liquify(before, s);
            s.Position = 0;
            ClassWithAccessors cr = (ClassWithAccessors)Liquifer.Solidify(s);

            Assert.AreEqual(29, after.Property1);
            Assert.AreEqual(10, after.Property2);

            Assert.AreEqual(1, info.ValueCount);

            
        }
    }
}
